package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.pubdef.dto.position.PositionConfigDTO;
import com.qumitech.visualnovel.pubdef.pubenum.OperationPositionTypeEnum;
import com.qumitech.visualnovel.service.position.PositionConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: yilu
 * @Date: 2019/5/28 16:18
 * @Description:
 */
@RestController
@RequestMapping("/api/position")
public class PositionController {
    @Autowired
    private PositionConfigService positionConfigService;

    @GetMapping("/hall")
    public BaseRsp getHallOperationPosition(@RequestParam(value = "offset",defaultValue = "0") Integer offset,
                                            @RequestParam(value = "limit",defaultValue = "20") Integer limit,
                                            @RequestParam(value = "app_version", required = false) String appVersion,
                                            @RequestParam(value = "app_channel", required = false) String appChannel){
        return new BaseRsp(ResultEnum.SUCCESS, positionConfigService.getPositionCfg(OperationPositionTypeEnum.Hall, offset, limit, appVersion, appChannel));
    }

    @PostMapping("/hall")
    public BaseRsp addHallOperationPosition(@RequestBody PositionConfigDTO positionConfigDTO){
        positionConfigDTO.setViewType(OperationPositionTypeEnum.Hall.getPositionType());
        if(positionConfigDTO.getPositionVersionChannelDTO() != null){
            positionConfigDTO.getPositionVersionChannelDTO().setViewType(OperationPositionTypeEnum.Hall.getPositionType());
        }
        positionConfigService.addPositionCfg(positionConfigDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PutMapping("/hall")
    public BaseRsp updateHallOperationPosition(@RequestBody PositionConfigDTO positionConfigDTO){
        positionConfigService.updatePositionCfg(positionConfigDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
}
